package bb.lanxing.util.ui;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import bb.lanxing.R;
import bb.lanxing.util.DensityUtil;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;

public class BaseBottomSheetDialogFragment extends BottomSheetDialogFragment {
    private BottomSheetBehavior<FrameLayout> behavior;
    private int topOffset = DensityUtil.dp2px(30.0f);

    @Override
    public Dialog onCreateDialog(Bundle bundle) {
        if (getContext() == null) {
            Dialog onCreateDialog = super.onCreateDialog(bundle);
//            Intrinsics.checkNotNullExpressionValue(onCreateDialog, "{\n            super.onCr…dInstanceState)\n        }");
            return onCreateDialog;
        }
        return new BottomSheetDialog(requireContext(), R.style.TransparentBottomSheetStyle);
    }

    @Override
    public void onStart() {
        super.onStart();
        try {
            Dialog dialog = getDialog();
            Intrinsics.checkNotNull(dialog);
            Window window = dialog.getWindow();
            Intrinsics.checkNotNull(window);
            window.setSoftInputMode(2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getHeight() {
        if (getContext() != null) {
            Object systemService = requireContext().getSystemService(Context.WINDOW_SERVICE);
//            Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.view.WindowManager");
            Point point = new Point();
            ((WindowManager) systemService).getDefaultDisplay().getSize(point);
            return point.y - getTopOffset();
        }
        return 1920;
    }

    public int getTopOffset() {
        return this.topOffset;
    }

    public void setTopOffset(int i) {
        this.topOffset = i;
    }

    public BottomSheetBehavior<FrameLayout> getBehavior() {
        return this.behavior;
    }
}
